<!doctype html>

<head>
    <meta name="Generator"  />
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width">
    <title>确认订单</title>
    <meta name="Keywords" content="Call管家" />
    <meta name="Description" content="Call管家" />
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>

    <link rel="stylesheet" href="__HOMECSS__/style.css">
    <script src="__HOMEJS__/jquery-1.7.2.min.js"></script>


</head>

<body style="margin-bottom: 60px;">

<!-- 确认订单 -->

<div class="confirm_address">
    <div class="confirmaddress_l">
        <img src="__HOMEIMG__/order_03.png" alt="" width="100%">
    </div>

    <a href="{:Url('User/info',['is_cart'=>1])}" style="display:block;" class="confirmaddress_r">
        {if condition="empty($user_info['mobile'])"}
            <p>请完善联系方式</p>
            {else/}
            <p class="namephone"><span>称呼：{$user_info.surname}{$user_info['sex']==1?'先生':'女士'}</span> <span>{$user_info.mobile}</span></p>
            <p class="address"><span>住址：万泰春天 {$user_info.address}</span><span style="float: right;">{$user_info.car_number}</span></p>
        {/if}
    </a>
</div>


{foreach name="cartList.cartList" item="item"}
    {if condition="$item.is_checked eq 1"}
        <a href="{:Url('Goods/detail',['id'=>$item['goods_id']])}" class="confirm_product" style="display: block">
            <div class="content_img confirm_product_img">
                <img src="{$item.goods_image_small}" alt="" width="100%">
            </div>
            <div class="content_name confirm_product_name">
                <p class="name">{$item.goods_name}</p>
                <p class="attr">{$item.attr_key_name}</p>
                <p class="price"><span>¥ {$item.price}</span> <span>x{$item.goods_num}</span></p>
            </div>
        </a>
    {/if}
{/foreach}

<div class="add_address confirm_delivery1">
    <span style="width: 20%;">优惠券</span>
    <div style="width: 80%;">
        <select name="coupon" id="coupon_input" style="background: #fff;height: 46px;color: #606060;direction: rtl;width: 100%;appearance: none;-moz-appearance: none;-webkit-appearance: none;">
            <option value="">{if condition="empty($coupon)"}没有可用服务券{else/}选择服务券{/if}</option>
            {foreach name="coupon" item="item"}
                <option value="{$item.id}">{$item.goods_name}</option>
            {/foreach}
        </select>
    </div>
</div>

<div  class="confirm_delivery confirm_delivery1">
    <span class="peisong">买家留言</span>
    <input placeholder="选填：对本次交易的说明" id="user_note_input" type="text"/>
</div>
<div class="confirm_amoutprice">
    <p><span>服务金额</span><span>¥ {$cartList.total_amount}</span></p>

</div>

<div class="confirm_rement">
    <span id="submit">提交订单</span>
    <span id="price">实付款：¥ {$cartList.total_amount}</span>

</div>

</body>

<script src="__PUBLIC__/layer/layer.js"></script>
<script>

    var total_amount = Number("{$cartList.total_amount}");
    var shipping = 0;
    var integral = Number("{$integral}")/Number("{$system_config.point_rate}");
    var coupon = 0;
    var useIntegral = -1;
    window.onload = function(){
        shop_cart.init();
    };
    var shop_cart ={

        init:function(){
            this.choseNum();
            this.getPrice();
        },
        choseNum:function () {
            $(".cut").click(function(){
                var num =parseInt($(this).parents(".chosenum1").find("input").val());
                if(num != 0){
                    num --;
                }
                $(this).parents(".chosenum1").find("input").val(num);
            })
            $(".add").click(function(){
                var num =parseInt($(this).parents(".chosenum1").find("input").val());
                if(num != 999){
                    num ++;
                }
                $(this).parents(".chosenum1").find("input").val(num);
            })
        },
        getPrice:function(){
            var price = total_amount*100 + shipping*100 - coupon*100;
            if(useIntegral > 0){
                price -= integral;
                $('#integral').text('-¥ '+integral/100);
            }else{
                $('#integral').text('-¥ 0');
            }
            $('#shipping').text('¥ '+shipping/100);
            $('#coupon').text('-¥ '+coupon/100);
            $('#price').text('实付款：¥ '+(price/100<0 ? 0 : price/100));
        }
    };

    $(function () {
        $(".circle").click(function () {
            if ( $(this).find('.small_y').hasClass('samll_yy') ){
                useIntegral = -1;
                $(this).find('.big_y ').css('background','#cdcdcd')
                $(this).find(".small_y").removeClass("samll_yy")
            }else {
                useIntegral = 1;
                $(this).find('.big_y ').css('background','#fe8258')
                $(this).find(".small_y").addClass("samll_yy")
            }
            shop_cart.getPrice();
        });
        $('#shipping_input').change(function(){
            var shipping_id = $(this).val();
            $.ajax({
                url:"{:Url('Order/calculateShippingPrice')}",
                data:{shipping_id:shipping_id},
                type:"post",
                dataType:"json",
                success:function(res){
                    if(res.code > 0){
                        shipping = res.result;
                        shop_cart.getPrice();
                    }else{
                        layer.msg(res.msg);
                    }
                }
            })
        });
        $('#coupon_input').change(function(){
            var coupon_id = $(this).val();
            $.ajax({
                url:"{:Url('Order/getCouponPrice')}",
                data:{coupon_id:coupon_id},
                type:"post",
                dataType:"json",
                success:function(res){
                    if(res.code > 0){
                        coupon = res.result;
                        shop_cart.getPrice();
                    }else{
                        layer.msg(res.msg);
                    }
                }
            });
            shop_cart.getPrice();
        });

        $('#submit').click(function(){
            $.ajax({
                url:"{:Url('Order/submit')}",
                data:{
                    user_note:$('#user_note_input').val(),
                    coupon_id:$('#coupon_input').val(),
                },
                type:"post",
                dataType:"json",
                success:function(res){
                    if(res.code > 0){
                        layer.msg(res.msg);
                        setTimeout(function(){
                            window.location.href = res.result;
                        },500);
                    }else{
                        layer.msg(res.msg);
                    }
                }
            })
        });

    })
</script>
</html>
